#!/usr/bin/python
# -*- coding: utf-8 -*-
# Created by binhou.li on 12/02/2018
# @Copyright

import config
import logging
import SocketServer
import utils
import SimpleHTTPServer
from BaseHTTPServer import HTTPServer
from multiprocessing import Pool, Process
from dcsNotifier import fileNotifier
import config


class fileServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    """
    class to process http request file operation
    """
    def do_POST(self):
        """
        Process http post request with json data
        :return:
        """
        pass



class fileForkingMixIn(SocketServer.ForkingMixIn):
    max_children = 5

class forkingFileServer(fileForkingMixIn, HTTPServer):
    pass

def run_fileserver():
    PORT = 2046
    handler = fileServerHandler
    http = forkingFileServer(("", PORT), handler)
    http.serve_forever()

if __name__ == '__main__':
    db_host = '10.69.130.43'
    db_user = 'dba'
    db_pass = 'mysql'
    db = 'dcs'
    watch_path = '/tmp/test'
    fn = fileNotifier(watch_path, db_host, db_user, db_pass, db)
    logging.info(" start Running Fileserver")
    p1 = Process(target=run_fileserver, args=())
    p2 = Process(target=fn.file_notify,args=())
    p1.start()
    p2.start()
    p1.join()
    p2.join()
